﻿using System;
using System.Data.SqlClient;
using AccessControl.Utility.ConnectionManager;


namespace AccessControl.DataAcess
{
	public static class Util
	{
		private static string _connectionString = "";

		internal static string ConnectionString
		{
			get
			{
                if (string.IsNullOrEmpty(_connectionString))
				{
					var connectionStringManager = new ConnectionStringManager("AccessControl");
					_connectionString = connectionStringManager.GetConnectionString();
				}
				return _connectionString;
			}
		}

		public static DateTime GetServerDateTime()
		{
			using (var cn = new SqlConnection(ConnectionString))
			{
				var cmdSelect = new SqlCommand(
					"SELECT getdate()", cn);
				cn.Open();
				var serverDateTime = (DateTime)cmdSelect.ExecuteScalar();
				cn.Close();
				return serverDateTime;
			}
		}
	}
}
